package com.latefly.skewwork.ui.page.practice

import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension

@Composable
fun ConstrainLayoutContent() {
    ConstraintLayout {
        val (button, text) = createRefs()
        Button(
            modifier = Modifier.constrainAs(button) {
                top.linkTo(parent.top, margin = 16.dp)
            },
            onClick = { }
        ) {
            Text(text = "Button")
        }
        Text(
            modifier = Modifier.constrainAs(text) {
                top.linkTo(button.bottom, margin = 16.dp)
                centerHorizontallyTo(parent)
            },
            text = "Text"
        )
    }
}


@Composable
fun ConstrainLayoutContent2() {
    ConstraintLayout {
        val (button1, button2, text) = createRefs()
        Button(
            modifier = Modifier.constrainAs(button1) {
                top.linkTo(parent.top, margin = 16.dp)
            },
            onClick = { }
        ) {
            Text(text = "Button1")
        }
        Text(
            modifier = Modifier.constrainAs(text) {
                top.linkTo(button1.bottom, margin = 16.dp)
                centerAround(button1.end)
                centerHorizontallyTo(parent)
            },
            text = "Text"
        )
        //组合Button1 Text组合为屏障
        val barrier = createEndBarrier(button1, text)
        Button(
            modifier = Modifier.constrainAs(button2) {
                top.linkTo(parent.top, margin = 16.dp)
                start.linkTo(barrier)
            },
            onClick = { }
        ) {
            Text(text = "Button2")
        }
    }
}


//换行形式的文本
@Composable
fun LargeTextContent() {
    ConstraintLayout {
        val text = createRef()
        val guideLine = createGuidelineFromStart(fraction = 0.5f)
        Text(
            modifier = Modifier.constrainAs(text) {
                start.linkTo(guideLine)
                end.linkTo(parent.end)
                //设置文本包裹设置自动换行
                width= Dimension.preferredWrapContent
            },
            text = "qqqwertyuiopasdfghjklzxcvbnm"
        )

    }
}